package com.haha.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditViewActivity extends AppCompatActivity {

    private Button btn_login;

    private EditText et_username;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_view);
        btn_login = (Button)findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(EditViewActivity.this,"登录事件触发！",Toast.LENGTH_SHORT).show();
            }
        });
        //监听用户名输入框的变化
        et_username = (EditText) findViewById(R.id.et_username);
        et_username.addTextChangedListener(new TextWatcher() {
            @Override
            //文字改变前
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }
            //文字改变时
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                Log.d("Username监听中===>",charSequence.toString());
            }
            //文字改变后
            @Override
            public void afterTextChanged(Editable editable) {

            }
        });


    }
}